IFF EXTRACTION, EDITING AND INSERTION v.1.1
-------------------------------------------

Thursday, 6 November 2003
Author: Vag
E-mail: vag@greekroms.f2s.com
Translation group: GreekRoms (www.greekroms.net)


1. Table of contents
--------------------

1. Table of contents
2. Essential programs and tools
3. IFF specifications
4. IFF extraction
5. IFF editing
6. IFF insertion
7. Web links
8. History
9. Credits



2. Essential programs and tools
-------------------------------

For the IFF extraction you only need a hex editor, it doesn't matter if it supports tables. I like Hex Workshop.
You may want a program only for viewing IFF pictures in windows. ACDC supports IFFs, just don't use it for editing because it saves them as large files.
You'll also need ADFView, an astonishing program that is a Windows Explorer extension to support adf files. You'll be able to open adf files in windows explorer as if they were folders and see more properties.
You'll need an Amiga emulator, UAE or Fellow.
Finally, you need a graphics-editing program that fully supports IFFs, that could be Deluxe Paint (versions I to V). You will run this under the Amiga emulator.
You may want to find Kick off 2 rom for the Amiga because the examples in this tutorial use this game. (It's legal to have it, Anco has given their permission).
You will also need my subsidiary files for Kick off 2 hacking, pen and paper.



3. IFF specifications
---------------------

"EA IFF 85" is Electronic Arts' standard for interchange format files.
It may deal with any kind of data, text, sound, graphics, fonts, video, etc.
Even new kinds of IFF files may be created in the future...
IFF files are constructed entirely of chunks. A chunk is a data structure containing a 4-byte ID, a 4-byte size value and possibly a block of data.
Each chunk is the same, simple structure and differs only in the data it contains.
Learning everything about all kinds of chunks is not so important for the aim of this tutorial though.
The most important kind of IFF is the ILBM interleaved bitmap, which is an IFF for graphics.

Its specifications are:

Type: bitmap
Colors: 1 to 24-bit
Compression: RLE or no compression
Maximum image size: 64Kx64K pixels
Multiple images per file: Yes
Numerical format: Big endian
Originator: Electronic Arts Inc., Commodore-Amiga Inc.
Platform: Amiga, PCs, Macintosh, others




4. IFF extraction
-----------------

At this moment, there isn't any program to help you with this process, so everything has to be done manually.
For example let's say you have Kick off 2 rom for the Amiga, open it with the hex editor (Hex Workshop).
To be able to extract a file, you have to know its start and end in the rom.

Search for the word "FORM" (this word is the beginning of the IFF files).
In other games you may find another word that contains this, for example "information", just ignore it if it's found.
Write down the offset address of the beginning of the word FORM and press F3 to find the next one.
Do the same and write all the offset addresses in one row.
If you do it correctly, you find the word FORM 22 times. That's how many IFF files you'll extract. (That's for the Ko2 rom).

Go to the beginning of the rom and do the same with the word BODY.
Write all the offset addresses in a second row.
If you do that correctly as well, you find the word BODY 22 times.

You will need to search the rom once more, to find the size of the BODY data.
Go to the beginning of the rom again and search for the word BODY again.
This time, you have to write the values of the 4 characters that are next to the word BODY.
The values of these 4 characters are an 8-digit number.
Usually, the first 4 numbers are 0000 because the IFF files aren't that big.
If a number is odd, you have to add 1 to it.
Remember that they are hexadecimal numbers. You can use the windows calculator in scientific view with "hex" selected.
A number is odd if the last digit is 1,3,5,7,9,B,D or F.
Write all these numbers in the third row, next to the BODY addresses.

Now you have everything you need to calculate the end of each file.
This means you have to use the calculator again.
For each pair of the BODY addresses and the BODY size numbers, you have to make an addition.
Do (BODY offset address) + (BODY data size) + 8 and write the result in a fourth row. This result is the end of the IFF file! You have to add 8 because the BODY data size doesn't count the word BODY (4 characters) and itself (another 4 characters).

If you do everything correctly, the first and last rows give you the start and end of all the IFF files in the rom.

Next step is to extract them.
For each one of the files, you need to do the following:
Go to the address of the fourth row, the end of the IFF.
Hold Shift pressed and press up arrow or page up, to select the portion of the rom until you find the word FORM.
You should be able to find it easily because you know the address and you can see it easily.

Copy the selection.
Create a new file with the Hex editor.
Paste into the new file.
Save the new file with .iff at the end of the filename.

Now you can use a windows viewer like ACDC to see the IFF file.
Note that you may have extracted an IFF of another kind, like sound IFF (not in Kick off 2).




5. IFF editing
--------------

If you have extracted an IFF that doesn't use compression, it will be easier for you to edit it because it will always have the same size in bytes.
If it uses compression, the size of the edited IFF will probably be different.
The problem is that if it's bigger in size, it can't be inserted in the rom again!
(The IFFs in Kick off 2 use compression.)

Let's assume you already have extracted all the IFF files in Ko2.
Unfortunately you can't convert them to another format, like BMP or JPG to edit them in an editor in windows.
The reason is that you need to maintain the same palette and IFF format.
If you find a windows program that can do that, then you should use it.
Until you find that, you have to use Deluxe Paint for the Amiga.

So, first you have to make an adf file that includes the IFF files you want to edit. (Maybe many adf files, to have much free space in them).

If you have installed ADFView, you can create a new adf document.
Then just drug and drop the IFF files you want into it.

Use your Amiga emulator to run Deluxe Paint.
You may want to make a configurations file (in UAE) to launch it more easily next time.
You can also save a state with Deluxe Paint loaded, to load it every time and not wait for it to load.
(Beware, it may need to put out and in any second disk to refresh the files list).

I won't explain to you how to use Deluxe Paint as I just started using it myself and I don't know it well.
If you keep the right mouse button pressed, then the drop down menu appears. You can also use the keyboard for some functions; you'll see the keys in the drop down menus.
The main objective here is to keep the size of the edited file smaller than the original one.
Keep in mind that if the picture has more details, it will probably be bigger in size.

For example, with the loading screen in Ko2, I added some letters in the picture and it became bigger.
I did a trick to reduce the size by putting two black horizontal lines up and down in the image. Very small ones, their height was 3 pixels I think.
The point is that these black lines can be compressed very much, so they still are a part of the IFF file, they are just very small in size.
They are so small that you don't notice it.




6. IFF insertion
----------------

Say you have made some modifications to a file and it's not bigger than the original one.
Again, you have to use the hex editor.
Open both IFFs in the hex editor.
You'll see that not only the BODY data is different, but the chunks before the BODY chunk are different as well.
Go to the beginning of the original file and select from the beginning (word FORM) to the word BODY.
Copy the selection.
Select the same things in the modified file and paste.
You have to keep the original chunks that precede the BODY chunk.
After you have done this, save a copy of the new IFF file.
If you're lucky it won't become bigger than the original file.

At this stage, you have a new IFF file that you can insert into the rom.
You know the beginning in the rom but the new file is probably a little smaller than the original one.
You just have to find the new end address of the file in the rom.
You have to add the size of the new IFF to the offset address of the word FORM in the rom.
If you do this correctly, you will find the address that is the end of the new IFF.

Select the whole new IFF in the hex editor.
Open the rom in the hex editor and go to the new end you just found (it should be before the end of the original IFF).
Press Shift and up or page up to select up to the word FORM.
Just paste to replace.

The new IFF has been inserted!
You always have to check and see if the rom is working, just in case anything has gone wrong.
(You must always keep copies after you do something successfully).




7. Web links
------------

Where to find the essential tools:

www.acdsystems.com    (ACDC)
www.viksoe.dk/adfview (ADFView)
www.bpsoft.com        (Hex Workshop)
www.zophar.net        (The Amiga emulators, other hex editors)
amiga.supergamez.hu   (Deluxe Paint IV)
www.greekroms.net     (The greek translation of Kick off 2)

More information about IFF files:

www.users.bigpond.com/james.jabobs/reg/EA_IFF.txt ("EA IFF 85" Standard for Interchange format files, written by Jerry Morrison, one of the creators of IFF)
www.gangstah.net/portal/Fileformats/IFFILBM.stm (Description of the IFF-ILBM file format)
netghost.narod.ru/gff/graphics/summary/iff.htm (IFF)
www.lightwave.3d.com.cn/lwsdk/lw75docsdk/filefmts/ilbm.htm ("ILBM" IFF Interleaved Bitmap)
www.borg.com/~jglatt/tech/aboutiff.htm
www.quux.org:70/Archives/mirrors/textfiles.com/programming/AMIGA/iff.txt (Intro to Amiga IFF ILBM Files and AMIGA Viewmodes, written by Carolyn Scheppner, Commodore Amiga Technical support)
www.users.bigpond.com/james.jacobs/reg/iff.html (IFF FORM and chunk registry - 12 March 2003)




8. History
----------

v.1.0
22 June 2003
Initial release

v.1.1
29 September 2003
Some corrections




9. Credits
----------

Most of the corrections in v.1.1 were made by Reham!

(c) 2002-2003 GreekRoms
(http://www.greekroms.net)
